package com.huicoo.forestmanager.widget;

import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.huicoo.forestmanager.R;
import com.huicoo.forestmanager.ui.media.CaptureVideoActivity;
import com.huicoo.forestmanager.ui.media.TakePhotoActivity;

/**
 * --------- 日期 ------- 维护人 ------------ 变更内容 --------
 * 2019/4/10	    Administrator
 * 照相机选择功能dialog
 */
public class CameraSelectionDialog extends AlertDialog implements View.OnClickListener {

    public CameraSelectionDialog(Context context) {
        super(context, R.style.ActionSheetDialogStyle);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.widget_camera_selection_dialog);
        Window win = getWindow();
        if (win != null) {
            win.getDecorView().setPadding(0, 0, 0, 0);
            WindowManager.LayoutParams lp = win.getAttributes();
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
            win.setAttributes(lp);
        }
        setCanceledOnTouchOutside(false);
        setCancelable(true);

        init();
    }

    private void init() {
        TextView btn_take_photo = findViewById(R.id.btn_take_photo);
        TextView btn_take_video = findViewById(R.id.btn_take_video);
        TextView btn_cancel = findViewById(R.id.btn_cancel);

        btn_take_photo.setOnClickListener(this);
        btn_take_video.setOnClickListener(this);
        btn_cancel.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_take_photo:
                gotoTakePhoto();
                dismiss();
                break;
            case R.id.btn_take_video:
                gotoTakeVideo();
                dismiss();
                break;
            case R.id.btn_cancel:
                dismiss();
                break;
            default:
                break;
        }
    }

    private void gotoTakePhoto() {
        Intent intent = new Intent(getContext(), TakePhotoActivity.class);
        getContext().startActivity(intent);
    }

    private void gotoTakeVideo() {
        Intent intent = new Intent(getContext(), CaptureVideoActivity.class);
        getContext().startActivity(intent);
    }

}
